package com.example.Controller;

import com.example.entity.Demo;
import com.example.mongodb.DemoDao;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/test")
public class TestController {

    @Resource
    private DemoDao demoDao;

    @RequestMapping("/save")
    public void save() {
        Demo demo = Demo.builder()
                .demoId("1")
                .username("admin")
                .password("123456")
                .build();
        demoDao.save(demo);
    }

    @RequestMapping("/findById")
    public Demo findById() {
       return demoDao.findById("1");
    }

    @RequestMapping("/update")
    public void update() {
        Demo demo2 = Demo.builder()
                .demoId("1")
                .username("test")
                .password("123456")
                .build();
        demoDao.update(demo2);
    }

    @RequestMapping("/removeById")
    public void removeById() {
        demoDao.removeById("1");
    }

}
